// JavaScript Document
define(function (require, exports, module) {
	var ThousandSeparatorNumber=require("module/control/ThousandSeparatorNumber");
	
	var ThousandSeparatorNumberInput=function(selector){
		this.element=$(selector).get(0);
		this.init()
	}
	ThousandSeparatorNumberInput.prototype.init=function(){
		var self=this;
		//$(this.element).bind("change",function(event){self.changeHandle(event)});
		$(this.element).bind("blur",function(event){self.thisEleBlur(event)});
	}
	ThousandSeparatorNumberInput.prototype.changeHandle=function(event){
		value=event.current.value;
		var value=this.element.value;
		this.$this=$(this.element);
		//this.getCloneEle();
		if(value){
			value=ThousandSeparatorNumber.eventEndFun(value);
			if(this.clone$this)this.clone$this.val(value);
		}else{
			console.log("use changeHandle but value is false;");
		};
	}
	//被克隆元素失去焦点时候触发的时间。王宇20160301
	ThousandSeparatorNumberInput.prototype.thisEleBlur=function(){
		var self=this;
		if(self.$this&&self.clone$this){
			self.clone$this.show();
		}else{
			return false;
		}
		var a =self.$this.prop("pattern");
		if(a){
			var chang=new RegExp(a);
			if(chang.test(self.$this.val())){
				self.clone$this.css({"border":"1px solid #ccc","color":"#000"});
			}else{
				self.clone$this.css({"border":"1px solid #f60","color":"#c00"});
			}
		}
		
	}
	//得到克隆元素，王宇20160301
	ThousandSeparatorNumberInput.prototype.getCloneEle=function(event){
		if(this.clone$this)return false;
		if(!this.$this)return false;
		this.createCloneEle();
		this.bindEventforCloneEle();
	}
	//创建克隆元素的方法，王宇20160301
	ThousandSeparatorNumberInput.prototype.createCloneEle=function(){
		this.clone$this=this.$this.clone();
		this.clone$this.attr({
			"name" : this.clone$this.attr("name") + "_clone",
			"id" : this.clone$this.attr("id")+"_clone"
		}).css({
			"position" : "absolute",
			"top" : this.$this.position().top + "px",
			"left" : this.$this.position().left + "px",
			"z-index" : 1000
		});
		this.$this.parent().append(this.clone$this);
	}
	//没有使用的删除方法，王宇20160301
	ThousandSeparatorNumberInput.prototype.removeCloneEle=function(){
		this.clone$this.remove();
		this.clone$this=" ";
	}
	//为克隆元素绑定事件的借口，王宇20160301
	ThousandSeparatorNumberInput.prototype.bindEventforCloneEle=function(){
		var self=this;
		this.clone$this.bind("focus",function(event){self.cloneElefocus()});
	}
	//克隆元素的获得焦点的方法，王宇20160301
	ThousandSeparatorNumberInput.prototype.cloneElefocus=function(){
		this.clone$this.hide();
		this.$this.focus();
	}
	module.exports = ThousandSeparatorNumberInput;
});